<?php
require_once '../lib/controller.php';

class action extends controller
{
	public function do_get()
	{
		$referer = isset($this->server['HTTP_REFERER']) ? $this->server['HTTP_REFERER'] : '';
		if( strpos($referer, 'logout') > 0 || empty($referer) )
		{
			$referer = 'index.php';
		}
		$this->view('www.login', array('referer'=>$referer));
	}

	public function do_post()
	{
		$db = $this->module('lib.db');
		$context = $this->get_context( array('db'=>$db) );
		$member = $this->module('biz.member', $context);
		if( $member->register() )
		{
			$this->msg($member->msg, 3, 'login.php');
		}else{
			$this->msg($member->msg);
		}
	}

	public function check_post()
	{
		$tool = $this->module('lib.tool');
		if( ! $tool->check_email($this->post['email']) || strlen($this->post['email']) > 30 || strlen($this->post['email']) < 6 )
		{
			$this->msg('邮箱格式不正确');
			return false;
		}
		if( strlen($this->post['password']) > 15 || strlen($this->post['password']) < 6 )
		{
			$this->msg('密码格式不正确');
			return false;
		}
		if( strlen($this->post['password2']) > 15 || strlen($this->post['password2']) < 6 )
		{
			$this->msg('重复密码格式不正确');
			return false;
		}
		if($this->post['password'] != $this->post['password2'] )
		{
			$this->msg('两次输入密码不一致');
			return false;
		}

		return true;
	}
}

$action = new action();
$action->run();
?>